﻿using System;
using System.Windows.Forms;

namespace SQLS
{
    public partial class frmPreview : Form
    {
        private string _filename;

        public string FileName 
        {
            get { return _filename; }
            set { _filename = value; } 
        }

        public frmPreview(string FileName)
        {
            InitializeComponent();
            _filename = FileName;
        }

        private void frmPreview_Load(object sender, EventArgs e)
        {
            codeBox.DecorationScheme = WinFormsCodeBox.Decorations.DecorationSchemes.SQLServer2008;
            cboFileType.SelectedIndex = 0;
        }

        private void cboFileType_SelectedIndexChanged(object sender, EventArgs e)
        {
            switch (cboFileType.SelectedIndex)
            {
                case 0: //plain
                    try
                    {
                        codeBox.LoadFile(_filename, RichTextBoxStreamType.PlainText);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("File is not in plain text format, please choose another");
                    }
                    break;
                case 1: //rtf                    
                    try
                    {
                        codeBox.LoadFile(_filename, RichTextBoxStreamType.RichText);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("File is not in rich text format, please choose another.");
                    }
                    break;
                case 2: //uni
                    try
                    {
                        codeBox.LoadFile(_filename, RichTextBoxStreamType.UnicodePlainText);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("File is not in unicode text format, please choose another.");
                    }
                    break;
            }
        }
    }
}
